package com.defang.award;

import com.defangit.award.domain.WinningInfo;
import com.defangit.award.domain.WinningStatus;
import com.defangit.award.orm.AwardService;
import com.defangit.award.orm.WinningInfoService;
import com.laogen.jersey_util.paged.PagerParams;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.EnumSet;
import java.util.List;

/**
 * Created by zhangfagen on 2019/1/3.
 */
@Path("winning")
public class WinningInfoResource {
    private WinningInfoService svr=new WinningInfoService();
    @GET @Produces("application/json")
    public Response all(@BeanParam()PagerParams pager,
                                 @QueryParam("award")int id,
                                 @QueryParam("user")String openid,
                                 @QueryParam("status") List<WinningStatus> status){
        return pager.toResponse(new WinningInfoService().findAll()
                .award(id)
                .user(openid)
                .status(status!=null?EnumSet.copyOf(status):null));
    }
    @POST @Produces("application/json")
    public WinningInfo attendAward(@QueryParam("award") int award){
        return svr.attendAward(award,"abc");
    }

    @PUT @Produces("application/json")
    public Response announcePrize(@QueryParam("once")Boolean once, @QueryParam("prize")Integer prize){
        return Response.ok(
                once!=null && once?svr.announcePrizeOnce(prize):svr.announcePrize(prize)
            ).build();
    }

}
